using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Microsoft.ConnectionEngine.SampleDeploymentManager.WizardPages
{
    public partial class RoutingEngineConfigPage : WizardPageBase
    {
        private const string ROUTING_HOST = "routinghost";
        private const string CONN_ENG_USER = "connenguser";
        private const string CONN_ENG_PASS = "connengpass";

        public RoutingEngineConfigPage()
        {
            InitializeComponent();
        }

        public override void Activate(ref Dictionary<string, object> parameters)
        {
            base.Activate(ref parameters);

            if (!_parameters.ContainsKey(ROUTING_HOST)) _parameters.Add(ROUTING_HOST, Utilities.GetCurrentHostName());
            if (!_parameters.ContainsKey(CONN_ENG_USER)) _parameters.Add(CONN_ENG_USER, "");
            if (!_parameters.ContainsKey(CONN_ENG_PASS)) _parameters.Add(CONN_ENG_PASS, "");

            if (_parameters.ContainsKey(ROUTING_HOST)) txtRSHost.Text = _parameters[ROUTING_HOST].ToString();
            if (_parameters.ContainsKey(CONN_ENG_USER)) txtCEUser.Text = _parameters[CONN_ENG_USER].ToString();
            if (_parameters.ContainsKey(CONN_ENG_PASS)) txtCEPass.Text = _parameters[CONN_ENG_PASS].ToString();
        }

        private void txtRSHost_Leave(object sender, EventArgs e)
        {
            if (_parameters.ContainsKey(ROUTING_HOST)) _parameters.Remove(ROUTING_HOST);
            _parameters.Add(ROUTING_HOST, txtRSHost.Text);
        }

        private void txtCEUser_Leave(object sender, EventArgs e)
        {
            if (_parameters.ContainsKey(CONN_ENG_USER)) _parameters.Remove(CONN_ENG_USER);
            _parameters.Add(CONN_ENG_USER, txtCEUser.Text);
        }

        private void txtCEPass_Leave(object sender, EventArgs e)
        {
            if (_parameters.ContainsKey(CONN_ENG_PASS)) _parameters.Remove(CONN_ENG_PASS);
            _parameters.Add(CONN_ENG_PASS, txtCEPass.Text);
        }
    }
}
